package com.lightbook.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lightbook.pojo.Admin;
import com.lightbook.pojo.Cart;
import com.lightbook.pojo.User;
import com.lightbook.result.Result;
import com.lightbook.service.AdminService;
import com.lightbook.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "后台登录管理")
@RestController
@RequestMapping("/admin/system/index")
public class AdminController {

    @Autowired
    private AdminService adminService;

    //    添加角色
    @ApiOperation(value = "新增角色")
    @PostMapping("/save")
    public Result save(@RequestBody Admin Admin) {
        boolean save = adminService.save(Admin);
        if (save) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    //  id查询角色
    @ApiOperation(value = "获取角色")
    @GetMapping("/get/{adminName}")
    public Result get(@PathVariable String adminName) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper();
        queryWrapper.eq("admin_name", adminName);
        List<Admin> list = adminService.list(queryWrapper);
        return Result.ok(list);
    }

}